
from abc import ABC , abstractmethod

# 抽象基类

class Shape(ABC):
    @abstractmethod
    def area(self):
        pass

    @abstractmethod
    def perimeter(self):
        pass

class Rectangle(Shape):
    def __init__(self, length, width):
        self.length = length
        self.width = width

    def area(self):
        return self.length * self.width

    def perimeter(self):
        return 2 * (self.length + self.width)


class Circle(Shape):
    def __init__(self, radius):
        self.radius = radius

    def area(self):
        return 3.14 * self.radius ** 2

    def perimeter(self):
        return 2 * 3.14159 * self.radius


rectangle = Rectangle(5, 10)

circle = Circle(7)

shapes = [rectangle, circle]
for shape in shapes:
    print(f"{shape.__class__.__name__} 的面积是 {shape.area():.2f}")
    print(f"{shape.__class__.__name__} 的周长是 {shape.perimeter():.2f}")